#include "Interpolation.h"

class F3:public Function
{
   public:
           double operator()(const double &x)const
           {
               if(x==0)
                   return 0;
               if(x==3)
                   return 225;
               if(x==5)
                   return 383;
               if(x==8)
                   return 623;
               if(x==13)
                   return 993;
               return 0;
           }
           double diff(const int &order,const double &x)const
           {
               if(x==0)
                   return 75;
               if(x==3)
                   return 77;
               if(x==5)
                   return 80;
               if(x==8)
                   return 74;
               if(x==13)
                   return 72;
               return 0;
           }
};

class G3:public Function
{
   public:
           double operator()(const double &x)const
           {
               if(x==0||x==1)
                   return 0;
               if(x==2||x==3)
                   return 3;
               if(x==4||x==5)
                   return 5;
               if(x==6||x==7)
                   return 8;
               if(x==8||x==9)
                   return 13;
               return 0;
           }
           double diff(const int &order,const double &x)const
           {
               return 0;
           }
};

int main()
{
     G3 g;
     F3 f;
     Subroutine Sub(f,g,9);
     Sub.generate();
     cout<<"position: "<<Sub.Hervalue(10)<<endl;
     cout<<"speed: "<<(Sub.Hervalue(10+epsl)-Sub.Hervalue(10-epsl))/(2*epsl)<<endl;
     
     double t=epsl;
     double diff;
     int result=0;
     while(t<=13-epsl)
     {
           diff=(Sub.Hervalue(t+epsl)-Sub.Hervalue(t-epsl))/(2*epsl);
           if(diff>81)
           {
               result=1;
               break;
           }
           t+=0.05;  
     }
     if(result=1)
           cout<<"the car had ever exceeded the limits"<<endl;
     else
           cout<<"the car had never exceeded the limits"<<endl;
     return 0;
}
